﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Karo
{
    public partial class GUI : Form
    {
        public GUI()
        {
            InitializeComponent();

            //DoubleBufferd drawing
            this.SetStyle(
            ControlStyles.UserPaint |
            ControlStyles.AllPaintingInWmPaint |
            ControlStyles.OptimizedDoubleBuffer, true);
        }


        Board _board;
        Game _game;

        private void btnStart_Click(object sender, EventArgs e)
        {
            _game = new Game();
            _board = _game.PlayingBoard;
            

            //The engine will do this later but for now we have it in c# just to get started with drawing
            _board.BoardSize = new System.Drawing.Size(30, 30);

            //Call the update of the picturebox we are going to draw on to start drawing
            pctDrawingBox.Invalidate();
        }

        private void pctDrawingBox_Paint(object sender, PaintEventArgs e)
        {
            //We need a board before we can draw something
            if (_board != null)
            {
                //Draw the board
                Drawing.DrawBoard(e.Graphics, _board, pctDrawingBox.Size);
            }
        }

        private void pctDrawingBox_Click(object sender, EventArgs e)
        {
            Point location = _board.GetClickedCoordinates(new Point(MousePosition.X - (this.Left + pctDrawingBox.Location.X) - 8, MousePosition.Y - (this.Top + pctDrawingBox.Location.Y) - 30));
            Tile clickedTile = _board.GetTileOnCoordinates(location);
            if (clickedTile != null)
                if (clickedTile.pawn != null)
                {
                    MessageBox.Show("Tile: " + clickedTile.Location.ToString() + "\nPlayer: " + clickedTile.pawn.belongsToPlayer.PlayerColor);
                    clickedTile.clicked = !clickedTile.clicked;
                    pctDrawingBox.Invalidate();
                }
                else
                    MessageBox.Show("Tile: " + clickedTile.Location.ToString());
        }

        private void GUI_Load(object sender, EventArgs e)
        {

        }

        private void GUI_Resize(object sender, EventArgs e)
        {
            pctDrawingBox.Invalidate();
        }


    }
}
